package com.medicine.hbp.ui;

import java.text.DateFormat;
import java.util.Calendar;

import org.kymjs.kjframe.http.HttpParams;
import org.kymjs.kjframe.ui.BindView;

import android.app.DatePickerDialog;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.medicine.hbp.R;
import com.medicine.hbp.base.BaseActivity;
import com.medicine.hbp.dialog.ChongfuDialog;
import com.medicine.hbp.dialog.ChongfuDialog.ChongfuDialogListener;
import com.medicine.hbp.dialog.ChongfuTimeDialog;
import com.medicine.hbp.dialog.ChongfuTimeDialog.ChongfuDialogTimeListener;
import com.medicine.hbp.http.AppHttpCallBack;
import com.medicine.hbp.http.AppHttps;
import com.medicine.hbp.http.HttpInterface;
import com.medicine.hbp.mob.findCareAboutListVo;
import com.medicine.hbp.picker.DatePicker;
import com.medicine.hbp.uitl.ToastUtil;

/**
 * 闹钟提醒设置
 *
 * @author Administrator
 */
public class AlarmRemindActivity extends BaseActivity {
	@BindView(id = R.id.layout_chongf, click = true)
	public LinearLayout layout_chongf;// 重复条目按钮
	@BindView(id = R.id.txt_chongf)
	public TextView txt_chongf;// 重复文字

	@BindView(id = R.id.text_lx01, click = true)
	public TextView text_lx01;// 老年人
	@BindView(id = R.id.text_lx02, click = true)
	public TextView text_lx02;// 中壮年
	@BindView(id = R.id.text_lx03, click = true)
	public TextView text_lx03;// 白领办公族
	@BindView(id = R.id.text_lx04, click = true)
	public TextView text_lx04;// 女性生理期

	@BindView(id = R.id.layout_time, click = true)
	public LinearLayout layout_time;// 时间点击

	@BindView(id = R.id.text_time)
	public TextView text_time;// 时间

	@BindView(id = R.id.img_view, click = true)
	public ImageView img_view;// 定时提醒

	private Calendar calendar;
	private int year, month, day, hour, monute, xingqi;
	private String time;

	private boolean lxBoolean01 = false;// 老年人 false 为选择 true 已选择
	private boolean lxBoolean02 = false;// 中壮年 false 为选择 true 已选择
	private boolean lxBoolean03 = false;// 白领办公族 false 为选择 true 已选择
	private boolean lxBoolean04 = false;// 女性生理期 false 为选择 true 已选择

	private boolean ImgBoolean = false;// 定时提醒 false 关 true 开
	private String status = "N";
	private String dateType="1";

	@Override
	public void setRootView() {
		super.setRootView();
		setContentView(R.layout.activity_alarmremind);
	}

	@Override
	public void initWidget() {
		super.initWidget();
		initTop();
		calendar = Calendar.getInstance();
		year = calendar.get(Calendar.YEAR);
		month = calendar.get(Calendar.MONTH);
		day = calendar.get(Calendar.DAY_OF_MONTH);
		hour = calendar.get(Calendar.HOUR_OF_DAY);
		monute = calendar.get(Calendar.MINUTE);
		xingqi = calendar.get(Calendar.DAY_OF_WEEK);
		time = year + "/" + month + "/" + day + " " + hour + ":" + monute;
		text_time
				.setText(year + "年" + month + "月" + day + "日 "
						+ DatePicker.getDayOfWeekCN(xingqi) + " " + hour + ":"
						+ monute);
	}

	@Override
	public void widgetClick(View v) {
		super.widgetClick(v);
		switch (v.getId()) {
			case R.id.img_view:// 重复性
				if (!ImgBoolean) {
					img_view.setImageResource(R.mipmap.swift_open);
					ImgBoolean = true;
					status = "Y";
				} else {
					img_view.setImageResource(R.mipmap.swift_closed);
					ImgBoolean = false;
					status = "N";
				}
				break;
			case R.id.layout_chongf:// 重复选择
				ChongfuDialog dialog = new ChongfuDialog(aty,
						new ChongfuDialogListener() {
							@Override
							public void onSelect(String content,String type) {
								txt_chongf.setText(content);
								dateType=type;
							}

							@Override
							public void onCancel() {

							}
						});
				dialog.showDetailEditDialog(txt_chongf.getText().toString());
				break;
			case R.id.layout_time:// 时间选择
				ChongfuTimeDialog dialog2 = new ChongfuTimeDialog(aty,
						new ChongfuDialogTimeListener() {
							@Override
							public void onSelect(String content, String stime) {
								text_time.setText(content);
								time = stime;
							}

							@Override
							public void onCancel() {
							}
						});
				dialog2.showDetailEditDialog();
				break;
			case R.id.text_lx01:// 老年人
				if (!lxBoolean01) {
					text_lx01.setBackgroundResource(R.drawable.alarm_remind_txt_back_shape02);
					text_lx01.setTextColor(getResources().getColor(R.color.white));
					lxBoolean01 = true;
				} else {
					text_lx01
							.setBackgroundResource(R.drawable.alarm_remind_txt_back_shape01);
					text_lx01.setTextColor(getResources().getColor(R.color.black));
					lxBoolean01 = false;
				}

				break;
			case R.id.text_lx02:// 中壮年
				if (!lxBoolean02) {
					text_lx02
							.setBackgroundResource(R.drawable.alarm_remind_txt_back_shape02);
					text_lx02.setTextColor(getResources().getColor(R.color.white));
					lxBoolean02 = true;
				} else {
					text_lx02
							.setBackgroundResource(R.drawable.alarm_remind_txt_back_shape01);
					text_lx02.setTextColor(getResources().getColor(R.color.black));
					lxBoolean02 = false;
				}
				break;
			case R.id.text_lx03:// 白领办公族
				if (!lxBoolean03) {
					text_lx03
							.setBackgroundResource(R.drawable.alarm_remind_txt_back_shape02);
					text_lx03.setTextColor(getResources().getColor(R.color.white));
					lxBoolean03 = true;
				} else {
					text_lx03
							.setBackgroundResource(R.drawable.alarm_remind_txt_back_shape01);
					text_lx03.setTextColor(getResources().getColor(R.color.black));
					lxBoolean03 = false;
				}
				break;
			case R.id.text_lx04:// 女性生理期
				if (!lxBoolean04) {
					text_lx04
							.setBackgroundResource(R.drawable.alarm_remind_txt_back_shape02);
					text_lx04.setTextColor(getResources().getColor(R.color.white));
					lxBoolean04 = true;
				} else {
					text_lx04
							.setBackgroundResource(R.drawable.alarm_remind_txt_back_shape01);
					text_lx04.setTextColor(getResources().getColor(R.color.black));
					lxBoolean04 = false;
				}
				break;
			default:
				break;
		}
	}

	/**
	 * 保存关心
	 */
	private void http() {
		HttpParams params = new HttpParams();
//		if (!lxBoolean01 && !lxBoolean02 && !lxBoolean03 && !lxBoolean04) {
//			ToastUtil.showShort(aty, "还未选择任何标签");
//			return;
//		}
		String laberType = "";
		if (lxBoolean01) {
			laberType+="1,";
		}
		if (lxBoolean02) {
			laberType+="2,";
		}
		if (lxBoolean03) {
			laberType+="3,";
		}
		if (lxBoolean04) {
			laberType+="4,";
		}
		params.put("status", status);// 是否提醒(Y 是 N 否)
		params.put("laberType", TextUtils.isEmpty(laberType)?"":laberType.substring(0, laberType.length()-1));// 标签(以逗号间隔)(1 老年人 2 中年人 3 白领办公族 4// 女性生理期)
		params.put("startDate", time);// 开始时间(yyyy/MM/dd HH:mm)
		params.put("dateType", dateType);// 时间类型(1 只此一次 2 每天 3 每周 4 周末 5 每月)
		AppHttps.HttpPost(aty, HttpInterface.SAVE_CARE_ABOUT_REMIND, params,
				new AppHttpCallBack<findCareAboutListVo>(
						findCareAboutListVo.class, aty) {
					@Override
					public void onSuccess(findCareAboutListVo result) {
						finish();
					}

					@Override
					public void onFailures(int errorCode, String errorMsg) {
						ToastUtil.showShort(aty, errorMsg);
						finish();
					}
				});

	}

	private void initTop() {
		TopView topview = (TopView) findViewById(R.id.topview);
		topview.setTitle("设置提醒");
		topview.setLeftVisibility(View.GONE);
		topview.setLeftVisibilityExit(View.VISIBLE);
		topview.setRightVisibility(View.INVISIBLE);
		topview.setLeftOnClickExit(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				http();

			}
		});
	}

}
